/*
 * Filename PreQrCodeVO.java 2022年10月20日
 * Copyright © Ehome Co.Ltd. All Rgiths Reserved.
 * @author wuyingchao
 */
package com.ehome.poct.core.api.vo.order;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author wyc
 * @since 2022/10/20 16:51
 **/
@Data
@ApiModel("支付前置-支付链接")
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class PreOrderRspVO {
    @ApiModelProperty("订单名称")
    private String orderName;
    @JsonUnwrapped
    @ApiModelProperty("支付链接")
    private QrCodeVO qrCode;
    @ApiModelProperty("创建时间")
    private LocalDateTime createTime;
    @ApiModelProperty("优惠总金额")
    private BigDecimal offerTotal;
    @ApiModelProperty("患者信息")
    private PrePatientVO patient;
    @ApiModelProperty("价格清单")
    private List<OrderItemPriceVO> priceItems;

    @ApiModelProperty("业务订单号")
    private String orderNo;

    @ApiModelProperty("是否支付成功")
    private boolean isPay;

    @ApiModelProperty("预约码")
    private String reservationCode;

    public BigDecimal getOfferTotal() {
        return priceItems.stream().filter(OrderItemPriceVO::getShowOfferMoney)
                .map(OrderItemPriceVO::getOfferMoney)
                .reduce(BigDecimal.ZERO, BigDecimal::add);
    }

    public String getOrderName() {
        return priceItems.stream().map(it -> {
            if (StrUtil.isBlank(it.getStripNameCn())) {
                return it.getStripNameEn();
            }
            return it.getStripNameEn() + "(" + it.getStripNameCn() + ")";
        }).collect(Collectors.joining("、"));
    }
}